home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / May MacUser Program.cpt / miniGenApp Src / AppInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  5.0 KB  |  171 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             AppInit.c
  3.     
  4.     DESCRIPTION:     Application Initialization Utilities
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  9.  
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     3.30.90    -    May 1990 MacUser Release
  14.     ==========================================================
  15.  
  16.    ***************************************************************************** */
  17. #include "AppGlobals.h"
  18. #include "MenuConstants.h"
  19.  
  20. #include "AboutBoxPr.h"
  21. #include "DocUtilPr.h"
  22. #include "ShellPr.h"
  23.  
  24. #include "AppInitPr.h"
  25.  
  26. /* -----------------  Local Constants  ---------------------------------- */
  27.  
  28. #define kMinSegSize        4096L        /* you estimate your minimum needs here */
  29. #define    kMastersNeeded    4            /* for pre-alloc of master pointers */
  30.  
  31. #define    kScreenBorder    4            /* these values in pixels */
  32. #define    kIconSize        32        
  33.  
  34.  
  35. /* ----------------------------  Local Prototypes  ------------------------------- */
  36. Boolean                    initMem         ( void );
  37. short                    setUpMenus         ( void );
  38.  
  39. /*----------------------------------------------------------------------------------------
  40.     initApp -    initialize the QD environment and the application state
  41.     3.30.90kwgm
  42. ----------------------------------------------------------------------------------------- */
  43. initApplication ()
  44. {
  45.     short         item;
  46.  
  47.     InitGraf(&thePort);    /* initialize the Mac managers */
  48.     InitFonts ();
  49.     InitWindows();
  50.     InitCursor ();    
  51.     InitMenus  ();
  52.     TEInit ();
  53.     InitDialogs (0L);
  54.     
  55.     splashScreen ();
  56.     
  57.     if (!initMem())            /* initialize application stuff */
  58.     {
  59.         StopAlert (kNotEnufMem, 0L);
  60.         ExitToShell ();
  61.     }
  62.     
  63.     setUpMenus();
  64.     
  65. } /* initApp */
  66.  
  67. /* ----------------------------------------------------------------------------------------
  68.     openAppDocs -    if opened from documents, open those documents. Else put new
  69.     3.30.90kwgm        document up. This is where double-clicking on a document opens
  70.                     that document
  71. ------------------------------------------------------------------------------------------ */
  72. void
  73. openAppDocs ()
  74. {
  75.     Boolean        openedOne;
  76.     
  77.     /* miniGenApp has no documents - for future use */
  78.     openedOne = false;
  79.     
  80.     if (!openedOne)
  81.         doNewDoc ();
  82.      
  83. } /* openAppDocs */
  84.  
  85. /* ----------------------------------------------------------------------------------------
  86.     initMem -    initialize application state/global variables
  87.     3.30.90kwgm
  88. ------------------------------------------------------------------------------------------ */
  89. static Boolean
  90. initMem ()
  91. {
  92.     register short     i;
  93.     short             resW, resH, menuBarHeight;
  94.     Size             sz;
  95.     Boolean            resultCode;
  96.     
  97.     MaxApplZone ();            /* maximize available memory */
  98.  
  99.     sz = FreeMem ();        /* get the available free memory */
  100.     
  101.     if (sz < kMinSegSize)
  102.         return (false);        /* not enough memory for our application */
  103.     
  104.     /* to avoid memory fragmentation, allocate master pointers at bottom of heap */
  105.     for (i = 0 ; i < kMastersNeeded ; i++)
  106.         MoreMasters();
  107.     
  108.     /* get screen dimensions */
  109.     resW = screenBits.bounds.right - screenBits.bounds.left;
  110.     resH = screenBits.bounds.bottom - screenBits.bounds.top;
  111.     menuBarHeight = GetMBarHeight();
  112.     
  113.     /* two global rectangles: one for the screen, the other for the default window size */
  114.     SetRect (&gScreenRect, kScreenBorder, menuBarHeight + kScreenBorder, resW - kScreenBorder, resH - kScreenBorder);
  115.     SetRect (&gWindowRect, kIconSize, menuBarHeight + kIconSize, resW - kIconSize, resH - kIconSize);
  116.     
  117.     /* what are we running on here? (need System 4.1 or greater) */
  118.     if (resultCode = SysEnvirons (1, &gSysEnv))
  119.     {
  120.         switch (resultCode) {
  121.             case envNotPresent:
  122.             case envBadSel:
  123.             case envSelTooBig:
  124.             default:
  125.                 StopAlert (kUnknownMach, 0L);    /* unknown environment */
  126.                 ExitToShell ();        /* leave the program here */
  127.                 break;
  128.         }
  129.     }
  130.     else
  131.     {
  132.         /* is WaitNextEvent implemented? - from Macintosh Tech Note #158 */
  133.         if (gSysEnv.machineType > envMachUnknown)
  134.             gHasWNE = NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9F, ToolTrap);
  135.         else
  136.             gHasWNE = false;        
  137.     
  138.         gHasColor = gSysEnv.hasColorQD;        /* this is a color QD machine */
  139.     }
  140.     
  141.     gDevel = true;            /* we are in development, this flag can be used
  142.                                 to turn on/off various debugging items 
  143.                                 that wouldn't be included in a production version */
  144.     
  145.     return (true);
  146.     
  147. } /* initMem */
  148.  
  149. /* ---------------------------------------------------------------------------------
  150.     setUpMenus -    set up the application menus
  151.     3.30.90kwgm
  152. -----------------------------------------------------------------------------------*/
  153. setUpMenus ()
  154. {
  155.     gDeskMenu = GetMenu (kAppleMenuID);
  156.     AddResMenu (gDeskMenu, 'DRVR');
  157.     InsertMenu (gDeskMenu, 0);
  158.     
  159.     gFileMenu = GetMenu (kFileMenuID);
  160.     InsertMenu (gFileMenu, 0);
  161.  
  162.     gEditMenu = GetMenu (kEditMenuID);
  163.     InsertMenu (gEditMenu, 0);
  164.  
  165.     DrawMenuBar();
  166.     
  167. } /* setUpMenus */
  168.  
  169. /* ===========================================  EOF  ========================================
  170.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  171. ============================================================================================ */